#include <stdio.h>
#include <string.h>
#include <algorithm>

int n, i, j;
int tu[10][10];
int cnt[10][10];
int getval(char ch)
{
    if (ch=='A') return 1;
    if (ch=='T') return 10;
    if (ch=='J') return 11;
    if (ch=='Q') return 12;
    if (ch=='K') return 13;
    return ch-'0';
}    

bool init()
{
    char tmp[5];
    if (scanf("%d", &n)==EOF) return false;
    for (i=1; i<=n; ++i)
        for (j=1; j<=n; ++j)
        {
           scanf("%s", tmp);
           tu[i][j] = getval(tmp[0]);
        }    
    return true;    
}    
void deal()
{
    int ans, x, y, maxv;
    for (i=1; i<=n; ++i)
        for (j=1; j<=n/2; ++j)
           std::swap(tu[i][j], tu[i][n-j+1]);
    cnt[1][1] = tu[1][1];
    for (int k=3; k<=n*2; ++k)
    {
        for (x=1; x<k; ++x)
        {
            maxv = 0;
            y = k-x;
            if (x>1 && maxv<cnt[x-1][y]) maxv = cnt[x-1][y];
            if (y>1 && maxv<cnt[x][y-1]) maxv = cnt[x][y-1];
            cnt[x][y] = tu[x][y] + maxv;
        }    
    }        
    printf("%d\n", cnt[n][n]);
}    
int main()
{
    while (init())
    {
        deal();
    }        
    return 0;    
}    

